package myLink;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/23-下午3:39
 * Since  :   1.0
 * Version:   1.0
 */
public class TwoMyHeroLink {
    public TwoHero head = new TwoHero(0, "", "");

    public void add(TwoHero twoHero) {
        TwoHero temp = head;
        while (true) {
            if (temp.next == null) {
                temp.next = twoHero;
                twoHero.pre = temp;
            }


            temp = temp.next;
        }


    }

    public void addByID(TwoHero twoHero) {
        TwoHero temp = head;
        Boolean flag = false;
        while (true) {
            if (temp.next == null) {
                break;
            }

            if (temp.next.no == twoHero.no) {
                flag = true;
                break;
            } else if (temp.next.no > twoHero.no) {
                break;
            }


            temp = temp.next;
        }
        if (flag) {
            System.out.println("the node is Already exists");
        } else {

            if (temp.next == null) {
                add(twoHero);

            } else {
                twoHero.next = temp.next;
                temp.next.pre = twoHero;

                temp.next = twoHero;
                twoHero.pre = temp;

            }


        }


    }

    public void del(int no) {
        TwoHero temp = head;
        if (temp.next == null) {
            System.out.println("空链表");
        }
        boolean flag = false;
        while (true) {

            if (temp.no == no) {
                flag = true;
                break;
            }

            if (temp.next == null) {
                break;
            }
            temp = temp.next;
        }

        if (flag) {
            if (temp.next!=null){

                temp.next.pre=temp.pre;
            }
            temp.pre.next=temp.next;

        } else {
            System.out.println("no such node");
        }


    }


}
